package com.example.demo.thread;

/*public class MyThread extends Thread {
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() +":"+ i);
        }
    }

    public static void main(String[] args) {
        new MyThread().start();
    }
}*/
/*
public class MyThread implements Runnable {

    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }

    public static void main(String[] args) {
        new Thread(new MyThread()).start();
    }
}*/

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyThread implements Callable<Integer> {

    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += i;
        }
        return sum;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyThread td = new MyThread();
        FutureTask<Integer> result = new FutureTask<>(td);
        new Thread(result).start();

        Integer sum = result.get();
        System.out.println(sum);
    }
}